package com.example.popupsample.component;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.example.popupsample.R;
import com.example.popupsample.component.dto.InputPopupDto;

public class InputPopup extends Dialog {

	private UserActionListener mListener;
	
	/**
	 * Constructor
	 * @param context
	 */
	
	public InputPopup(Context context,InputPopupDto popupDto) {
		super(context);
		this.init(popupDto);
	}

	private void init(InputPopupDto popupDto){
		this.setContentView(R.layout.input_popup);
		
		if(popupDto.title == null) {
			this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		} else {
			this.setTitle(popupDto.title);
		}
		
		TextView tv = ((TextView)this.findViewById(R.id.popupContent));
		tv.setText(popupDto.content);
		
		Button bt = ((Button)this.findViewById(R.id.confirm));
		bt.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				TextView tv = ((TextView)findViewById(R.id.inputBox));
				if(mListener != null) {
					mListener.onInputText(tv.getText().toString());
				}
			}
		});
	}
	
	public interface UserActionListener {
		public void onInputText(String text);
	}
	
	public void setUserActionListener(UserActionListener listener) {
		this.mListener = listener;
	}
}
